/**
 * Created by hps on 17-4-27.
 */
public class HighArray {
    private long[] a;
    private int nElems;

    public HighArray(int max) {
        a = new long[max];
        nElems = 0;
    }

    public boolean find(long searchKey) {
        int j;
        for(j = 0; j < nElems; j++)
            if(a[j] == searchKey)
                return true;
        return false;
    }

    public void insert(long value) {
        a[nElems++] = value;
    }

    public boolean delete(long value) {
        int i;
        for(i = 0; i < nElems; i++)
            if(a[i] == value)
                break;
        if (i == nElems)
            return false;

        for (int j = i; j < nElems - 1; j++)
            a[j] = a[j + 1];
        nElems--;
        return true;
    }

    public void display() {
        for (int i = 0; i < nElems; i++) {
            System.out.print(a[i] + " ");

        }
        System.out.println();
    }

    public long getMax() {
        if(nElems == 0)
            return -1;
        long max = a[0];
        for(int i = 1; i < nElems; i++)
            if(max < a[i])
                max = a[i];
        return max;
    }

    public long removeMax() {
        if(nElems == 0)
            return -1;
        long max = a[0];
        for(int i = 1; i < nElems; i++)
            if(max < a[i])
                max = a[i];
        delete(max);
        return max;
    }
}
